﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace HotelManger2012
{
    public partial class Form7 : Form
    {
        
        Form1Manager form = new Form1Manager();
        int iloscPokoi = new int();
        int ile_osobowy = new int();
        int temp = 0;int temp2=0;
        int i = 0;
       
        

        public Form7()

        {
            InitializeComponent();
            label4.Text = Convert.ToString(form.pokoje.Length);
             
             
        }

        private void Form7_Load(object sender, EventArgs e)
        {
           
        }

        private void button1_Click(object sender, EventArgs e)
        {

            if (!int.TryParse(textBox3.Text, out iloscPokoi)||temp+iloscPokoi>form.pokoje.Length||!int.TryParse(textBox2.Text, out ile_osobowy ))
            {
                MessageBox.Show("Bledny wpis", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

            }
            else
            {
                temp2=Convert.ToInt32(textBox3.Text);
                ile_osobowy = Convert.ToInt32(textBox2.Text);

                while( i < temp2+temp)
                {
                    form.pokoje[i].ileOsobowy = ile_osobowy;
                    listBox1.Items.Add( form.pokoje[i].ileOsobowy+" "+i );
                    
                    i++;

                }

                temp += iloscPokoi;
                

                listBox1.Items.Add("Dodano " + iloscPokoi+" pokoi "+ile_osobowy+" osobowych");
                
                iloscPokoi = 0;
                label4.Text = Convert.ToString(form.pokoje.Length-temp);
               

            }

        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            
           
           

           

        }

        private void textBox1_Validated(object sender, EventArgs e)
        {

        }

        private void textBox1_Validating(object sender, CancelEventArgs e)
        {
            
        }

        private void Form7_FormClosed(object sender, FormClosedEventArgs e)
        {
            zapisUtawien();
        }

        private void zapisUtawien()
        {
            string sciezka = "ustawieniapokoi.txt";

            StreamWriter zapis = new StreamWriter(sciezka);

            for (int i = 0; i < form.pokoje.Length; i++)
            {
                
                zapis.WriteLine(form.pokoje[i].ileOsobowy);
            }
            MessageBox.Show("Zapisano ustawienia :)");
            form.zapisPokoi();
            zapis.Close();
        }

        private void Form7_FormClosing(object sender, FormClosingEventArgs e)
        {
            
        }

       

        
    }
}
